import numpy as np
# 加载莺尾花数据集
from sklearn import datasets
# 导入KNN分类器
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import  train_test_split

# 导入莺尾花数据集
iris = datasets.load_iris()
print(iris)

X = iris.data
y = iris.target
# 得到训练集合和验证集合, 8: 2
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2)

# 训练模型
clf = KNeighborsClassifier(n_neighbors=5,p=2,metric="minkowski")
clf.fit(X_train,y_train)

# 预测
X_pred = clf.predict(X_test)
acc = sum(X_pred == y_test) / X_pred.shape[0]
print("预测的准确率ACC：%.3f" % acc)
